<?php
/**
 * unit test case for pathnode common libraries :
 * Pathnode, FolderNode and Filenode
 */
class TestPathNode extends UnitTestCase {

    function setUp() {
        // deleting test file
        // unlink(dirname(__FILE__).'/tmp.txt');
    }

    function testGetFile() {
        // echo $self_dir;
        $file=Pathnode::getnode(__FILE__);
        if (!$this->assertIsA($file,'pathnode')) {
            $this->dump(__FILE__);
            $this->dump($file);
            return false;
        }
        $this->assertNoErrors();
        $this->assertIsA($file,'filenode');
        $this->assertTrue($file->exists(),'pathnode->exists() should return true if file exists');
        $this->assertEqual($file->getbasename(),basename(__FILE__),'pathnode->getbasename should return fiel base name');
        $this->assertEqual($file->getAbsolutePath(),__FILE__);
        $this->assertEqual($file->getRelativePath(),substr(__FILE__,strlen(dirname($_SERVER['SCRIPT_FILENAME']))+1));
    }

    function testGetNull() {
        $tmp=Pathnode::getnode(dirname(__FILE__).'/tmp');
        $this->assertNoErrors();
        $this->assertNull($tmp,'pathnode::getnode should return null for non-existing nodes');
    }

    function testFolder() {
        $f=Pathnode::getnode(dirname(__FILE__).'/un dossier');
        if (!$this->assertIsA($f,'Foldernode','pathnode::getnode should get a Foldernode when path is a folder')) {
            $this->dump($f);
            return false;
        }

        $files=$f->getChildren();
        $this->assertIsA($files,'array','Foldernode->getChildren() should return an array');
        foreach ($files as $file) {
            $this->assertIsA($file,'Pathnode','Foldernode->getChildren() should return an array, of Pathnode objects');
        }

        $this->dump($f);
    }


}
?>
